package progress.exa30_1;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;

public class ConstructorStudy {
    public static void main(String[] args) throws InvocationTargetException, InstantiationException, IllegalAccessException {
        constructorStudy();
    }

    public static void constructorStudy() throws InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> cl = ArrayList.class;
        ArrayList arrayList = null;
        Constructor[] constructors = cl.getConstructors();
        for(Constructor constructor:constructors){
            System.out.println("构造器名称："+constructor.getName());
            Class[] classes = constructor.getParameterTypes();
            System.out.println("构造器参数：");
            for(Class zl:classes){
                System.out.print(zl.getName()+" , ");
            }
            if(classes.length==0){
                System.out.println("使用ArrayList的无参构造方法创建对象");
                arrayList = (ArrayList) constructor.newInstance();
                arrayList.add("Test");
                System.out.println(arrayList);
            }

            System.out.println();
        }
    }
}
